﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Criterion;
using System.Collections;

namespace Project.IManager
{
    public interface IManagerBase<T> where T : class
    {
        /// <summary>
        /// 通过主键返回对象
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
        T Get(object id);

        /// <summary>
        /// 保存对象
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns></returns>
        object Save(T model);

        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="model">实体</param>
        void Update(T model);

        /// <summary>
        /// 保存或更新对象
        /// </summary>
        /// <param name="model">实体</param>
        void SaveOrUpdate(T model);

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="model">实体</param>
        void Delete(T model);

        /// <summary>
        /// 删除对象 : 唐海华新增的
        /// </summary>
        /// <param name="id">主键值</param>
        void Delete(object id);

        /// <summary>
        /// 批量删除对象
        /// </summary>
        /// <param name="idList">主键集合</param>
        void Delete(List<long> idList);

        /// <summary>
        /// 获取所有记录
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetAll();

		/// <summary>
		/// 动态查询记录
		/// </summary>
		/// <param name="list"></param>
		/// <returns></returns>
		IList<T> GetList(IList<ICriterion> list);

		/// <summary>
		/// 动态查询记录
		/// </summary>
		/// <param name="list"></param>
		/// <returns></returns>
		IList<T> GetList(IList<ICriterion> list,IList<Order> orderList);

		/// <summary>
        /// 自定义查询(自定义 LINQ 查询语句)
        /// </summary>
		/// <param name="list"></param>
		/// <returnGetLists></returns>
		IList GetList(string queryString);

        /// <summary>
        /// 自定义查询(查找  Distinct columnName)
        /// </summary>
        /// <param name="columnName"></param>
        /// <returns></returns>
        IList<TT> GetDistinctList<TT>(string columnName);

        /// <summary>
        /// 获取记录总数
        /// </summary>
        /// <returns></returns>
        int GetCount();

        /// <summary>
        /// 获取记录总数
        /// </summary>
        /// <returns></returns>
        int GetCount(IList<ICriterion> list);

        /// <summary>
        /// 获取分页集合
        /// </summary>
        /// <param name="firstResult">开始记录</param>
        /// <param name="maxResult">行数</param>
        /// <returns></returns>
        IQueryable<T> GetPageList(int firstResult, int maxResult);

        IQueryable<T> FindPageList(System.Reflection.PropertyInfo sort, string dir, int firstResult, int maxResult);
		/// <summary>
		/// 获取分页集合
		/// </summary>
		/// <param name="total">返回记录数总数</param>
		/// <param name="sort">排序字段：通过反射获取：PropertyInfo pi = new T().GetType().GetProperty("Id");</param>
		/// <param name="dir">排序规则：ACS：升序。其他：降序</param>
		/// <param name="firstResult">开始记录数</param>
		/// <param name="maxResult">获取的总记录数</param>
		/// <returns></returns>
        IQueryable<T> FindPageList(out long total, System.Reflection.PropertyInfo sort, string dir, int firstResult, int maxResult);

        // 动态分页查询
        IList<T> GetPageList(int firstResult, int maxResult, IList<NHibernate.Criterion.ICriterion> list, NHibernate.Criterion.Order order);

        IList<T> GetPageList(Wuqi.Webdiyer.AspNetPager AspNetPager, IList<ICriterion> queryList, Order order);
        IList<T> GetPageList(Wuqi.Webdiyer.AspNetPager AspNetPager, IList<ICriterion> queryList, IList<Order> order);

    }
}
